/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Database.Koneksi;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author owner
 */
public class pemesanantoko {
    public boolean tambahPelanggan(String data){
            int has = 0;
            String [] dataArray=data.split("/");
            
            String hasil1 = "error error";
            Connection con = Koneksi.open();
            String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:XE";
            boolean hasil = false ; 
            String name = "HR";
            String pass = "dion";
            
            try {
                String query1 = "select ID_PESAN from PEMESANAN";
                PreparedStatement stat = con.prepareStatement(query1);
                ResultSet hasil2 = stat.executeQuery(query1);
                String a = new String();
                while (hasil2.next()) {
                    a = hasil2.getString("ID_PESAN");
                }
                int id = Integer.parseInt(a)+1;
    
    //        Statement stat = (Statement) con.createStatement();
            String query = " insert into PEMESANAN values(?,?,?,?,?,?)";
            PreparedStatement statement = con.prepareStatement(query);
            statement.setString(1,dataArray[0]);
            statement.setString(2,Integer.toString(id));
            statement.setString(3,dataArray[1]);
            statement.setString(4,dataArray[2]);
            statement.setString(5,dataArray[3]);
            statement.setString(6,"belumdikirim");    
                
//                statement.setString(4,dataArray[3]);
//                statement.setString(5,dataArray[4]);
//                statement.setString(6,dataArray[5]);
                
            has=statement.executeUpdate();
            con.commit();
        } catch (SQLException ex) {
            Logger.getLogger(pemesanantoko.class.getName()).log(Level.SEVERE, null, ex);
        }
            if ( has > 0  ) {
                hasil = true ;
            }
            return hasil;
        }
}